package cn.layku.order.util;

import com.fasterxml.jackson.annotation.JsonInclude;

public class ApiResult<T> {

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private int code;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private String message;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Long total;

    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Object summary;

    public ApiResult() {
    }

    private ApiResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    private ApiResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    private ApiResult(int code, String message, T data, Long total) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
    }

    private ApiResult(int code, String message, T data, Long total, Object summary) {
        this.code = code;
        this.message = message;
        this.data = data;
        this.total = total;
        this.summary = summary;
    }

    public static <T> ApiResult<T> successResult() {
        return new ApiResult<>(200, "success");
    }

    public static <T> ApiResult<T> successResult(String message) {
        return new ApiResult<>(200, message);
    }

    public static <T> ApiResult<T> successResultForData(T data) {
        return new ApiResult<>(200, "success", data);
    }

    public static <T> ApiResult<T> successResultForPage(T data, Long total) {
        return new ApiResult<>(200, "success", data, total);
    }

    public static <T> ApiResult<T> successResultForSummaryPage(T data, Long total, Object summary) {
        return new ApiResult<>(200, "success", data, total, summary);
    }

    public static <T> ApiResult<T> failResult(String message) {
        return failResult(500, message);
    }

    public static <T> ApiResult<T> paramIsNullFailResult(String message) {
        return failResult(101, message);
    }

    public static <T> ApiResult<T> paramCheckFailResult(String message) {
        return failResult(102, message);
    }

    public static <T> ApiResult<T> failResult(int code, String message) {
        return new ApiResult<>(code, message);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public Object getSummary() {
        return summary;
    }

    public void setSummary(Object summary) {
        this.summary = summary;
    }
}
